package com.sen.patterns.creational.builder.ex2;

import java.util.Iterator;
import java.util.List;

/**
 * 汽车装配类，根据builder提供的装配方法，按照装配步骤装配汽车
 * @author sen
 */
public class AutomobileDirector {

	// 装配步骤类
	AutoBuilder builder;
	
	public AutomobileDirector(AutoBuilder builder) {
		this.builder = builder;
	}

	// 这里是step-by-step的，不同于Abstract Factory
	public Automobile produceAuto(List input) {
		builder.buildBase();
		for (Iterator it = input.iterator(); it.hasNext();) {
			PartItem p = (PartItem) it.next();
			builder.addAutomobileItem(p);
			builder.checkAutomobileItem(p);
		}
		builder.testAutomobile();
		return builder.getFinishedAutomobile();
	}
}
